package com.dcms.admin.service.impl;

import com.dcms.admin.bean.Comment;
import com.dcms.admin.dao.CommentMapper;
import com.dcms.admin.service.ICommentService;
import com.dcms.util.ClassUtil;
import com.dcms.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.lang.reflect.Field;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * \* @name: CommentServiceImpl
 * \* @author: 武佳伟丶
 * \* @date: 2018/2/11 0011
 * \* @tine: 10:35
 * \* @description: To change this template use File | Settings | File Templates.
 * \
 */
@Service
public class CommentServiceImpl implements ICommentService{

    @Autowired
    private CommentMapper mapper;

    @Override
    public int deleteByPrimaryKey(Integer commentId) {
        return mapper.deleteByPrimaryKey(commentId);
    }

    @Override
    public int insertSelective(Comment record) {
        return mapper.insertSelective(record);
    }

    @Override
    public Comment selectByPrimaryKey(Integer commentId) {
        return mapper.selectByPrimaryKey(commentId);
    }

    @Override
    public int updateByPrimaryKeySelective(Comment record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    /**
     * @param param
     * @author: 武佳伟丶
     * @description: 根据条件查询所有的comment
     * @date: 10:40 2018/2/11 0011
     * @param: [param] 用于模糊查询content
     * @return: java.util.List<com.dcms.admin.bean.Comment>
     */
    @Override
    public List<Comment> selectAll(String param, Comment record) {
        Map map = new HashMap(1);
        if (param != null && !"".equals(param)){
            map.put("param", StringUtil.appendPerCent(param));
        }
        //只查询未删除的
        map.put("deleted", 1);
        map.putAll(ClassUtil.getFields(record));
        return mapper.selectAll(map);
    }

    /**
     * @param id
     * @author: 武佳伟丶
     * @description: 批量删除
     * @date: 14:31 2018/2/12 0012
     * @param: []
     * @return: int
     */
    @Override
    public int deleteBatch(Integer[] id) {
        return mapper.updateToDeletedBatch(id);
    }

}